﻿using DDU.DataModel;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Text;

namespace DDU.ViewModel
{
    public class CourseViewModel : MainViewModel
    {
        public CourseViewModel()
        {
            SelectedSemester = CurrentSemester;
        }

        public int PivotIndex
        {
            get
            {
                if (IsDesignMode)
                {
                    return 1;
                }
                return (int)DateTime.Today.DayOfWeek;
            }
        }

        private SemesterInfo selectedSemester;
        public SemesterInfo SelectedSemester
        {
            get { return selectedSemester; }
            set
            {
                selectedSemester = value;
                RaisePropertyChanged(() => SelectedSemester);
                RaisePropertyChanged(() => ItemsOfFriday);
                RaisePropertyChanged(() => ItemsOfMonday);
                RaisePropertyChanged(() => ItemsOfSaturday);
                RaisePropertyChanged(() => ItemsOfSunday);
                RaisePropertyChanged(() => ItemsOfThursday);
                RaisePropertyChanged(() => ItemsOfTuesday);
                RaisePropertyChanged(() => ItemsOfWednesday);
            }
        }

        public ObservableCollection<ScheduleInfo> ItemsOfSunday
        {
            get
            {
                if (SelectedSemester != null)
                {
                    return new ObservableCollection<ScheduleInfo>(Database.CollectionOfSchedules.Where(s => s.SemesterGuid == SelectedSemester.Guid && s.DayOfWeek == DayOfWeek.Sunday));
                }
                return null;
            }
        }

        public ObservableCollection<ScheduleInfo> ItemsOfMonday
        {
            get
            {
                if (SelectedSemester != null)
                {
                    return new ObservableCollection<ScheduleInfo>(Database.CollectionOfSchedules.Where(s => s.SemesterGuid == SelectedSemester.Guid && s.DayOfWeek == DayOfWeek.Monday));
                }
                return null;
            }
        }

        public ObservableCollection<ScheduleInfo> ItemsOfTuesday
        {
            get
            {
                if (SelectedSemester != null)
                {
                    return new ObservableCollection<ScheduleInfo>(Database.CollectionOfSchedules.Where(s => s.SemesterGuid == SelectedSemester.Guid && s.DayOfWeek == DayOfWeek.Tuesday));
                }
                return null;
            }
        }

        public ObservableCollection<ScheduleInfo> ItemsOfWednesday
        {
            get
            {
                if (SelectedSemester != null)
                {
                    return new ObservableCollection<ScheduleInfo>(Database.CollectionOfSchedules.Where(s => s.SemesterGuid == SelectedSemester.Guid && s.DayOfWeek == DayOfWeek.Wednesday));
                }
                return null;
            }
        }

        public ObservableCollection<ScheduleInfo> ItemsOfThursday
        {
            get
            {
                if (SelectedSemester != null)
                {
                    return new ObservableCollection<ScheduleInfo>(Database.CollectionOfSchedules.Where(s => s.SemesterGuid == SelectedSemester.Guid && s.DayOfWeek == DayOfWeek.Thursday));
                }
                return null;
            }
        }

        public ObservableCollection<ScheduleInfo> ItemsOfFriday
        {
            get
            {
                if (SelectedSemester != null)
                {
                    return new ObservableCollection<ScheduleInfo>(Database.CollectionOfSchedules.Where(s => s.SemesterGuid == SelectedSemester.Guid && s.DayOfWeek == DayOfWeek.Friday));
                }
                return null;
            }
        }

        public ObservableCollection<ScheduleInfo> ItemsOfSaturday
        {
            get
            {
                if (SelectedSemester != null)
                {
                    return new ObservableCollection<ScheduleInfo>(Database.CollectionOfSchedules.Where(s => s.SemesterGuid == SelectedSemester.Guid && s.DayOfWeek == DayOfWeek.Saturday));
                }
                return null;
            }
        }
    }
}
